package gold.digger;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC957 {
    public long startExecuteTime = System.currentTimeMillis();

    /*
      * @param 此题目参考了别人代码
      * 这是因为问题情况较为复杂
      * 大家的解法都太秀了，有人数学证明了N的循环周期为14
      * @return:
      */
    class Solution {
        public int[] prisonAfterNDays(int[] cells, int N) {
            N = (N - 1) % 14 + 1;
            while (N-- > 0) {
                int[] arr = new int[cells.length];
                for (int i = 1; i <= 6; i++) {
                    arr[i] = (cells[i - 1] == cells[i + 1]) ? 1 : 0;
                }
                cells = arr;
            }

            return cells;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] cells = {1, 0, 0, 1, 0, 0, 0, 1};
        System.out.println(Arrays.toString(solution.prisonAfterNDays(cells, 826)));
    }

    public static void main(String[] args) throws Exception {
        LC957 an = new LC957();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
//        测试结果:[1,0,0,1,0,0,0,1]
//        期望结果:[0,1,1,0,1,1,1,0]
//        stdout:
//
